import pandas as pd
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
from data_processing import data_processing
from model_train import SimplifiedEnsemble
from model_predict import model_predict
from evaluate_plt import evaluate_model
from data_distribution import ana_data
import joblib
plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'SimSun', 'FangSong', 'KaiTi']  # 指定一系列备选的中文字体
plt.rcParams['axes.unicode_minus'] = False  # 解决负号'-'显示为方块的问题

# 显示所有列
pd.set_option('display.max_columns', None)
# # 显示所有行
# pd.set_option('display.max_rows', None)
# # 不换行显示
pd.set_option('display.width', 1000)
# 行列对齐显示，显示不混乱
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
# 设置value的显示长度为100，默认为50
pd.set_option('max_colwidth', 100)



# 数据导入+特征提取
d1 = data_processing('../data/raw/train.csv', '../data/raw/test2.csv')
X_train, y_train, X_test, y_test, data = d1[0], d1[1], d1[2], d1[3], d1[4]
print(data.head())
# 特征分布分析
ana_data(data)
# 特征工程
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# 调出模型
study_ensemble = joblib.load('../model/魔杰大模型.pkl')
print("最佳参数:", study_ensemble.best_params)
# 训练最终模型
best_model = SimplifiedEnsemble(xgb_params=study_ensemble.best_params)
best_model.fit(X_train, y_train)

# 模型预测和评估
model_predict(best_model, X_train, y_train, X_test, y_test)
# 针对结果进行图像处理
evaluate_model(best_model, X_test, y_test)
